﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Company_Default : System.Web.UI.Page
{
    public string CompanyName, UserID, lb_gy, lb_cg, lb_dl, lb_hz, lb_tb, lb_rz, lb_cd, lb_qt, keywords;
    string sql;
    string tt = "" ,cc="";
    string pid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            info();
            list_bind();
        }
    }
    private void info()
    {
        if (Request.QueryString["p_UserID"] != "")
        {
            int uid = int.Parse(Request.QueryString["p_UserID"]);
            DataTable dt = Class1.ExecSel("select * from wj_User where wj_ID=" + uid + "");
            CompanyName = Convert.ToString(dt.Rows[0]["wj_CompanyName"].ToString());
            UserID = Convert.ToString(dt.Rows[0]["wj_ID"].ToString());
            keywords = Convert.ToString(dt.Rows[0]["wj_keywords"].ToString());
            SqlConnection conn = Class1.DBconnection();
            SqlDataAdapter da;
            DataSet ds = new DataSet();

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='供应'", conn);
            da.Fill(ds, "供应");
            string gy = ds.Tables["供应"].Rows.Count.ToString();
            lb_gy = gy;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='采购'", conn);
            da.Fill(ds, "采购");
            string cg = ds.Tables["采购"].Rows.Count.ToString();
            lb_cg = cg;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='代理'", conn);
            da.Fill(ds, "代理");
            string dl = ds.Tables["代理"].Rows.Count.ToString();
            lb_dl = dl;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='合作'", conn);
            da.Fill(ds, "合作");
            string hz = ds.Tables["合作"].Rows.Count.ToString();
            lb_hz = hz;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='招投标'", conn);
            da.Fill(ds, " 招投标");
            string tb = ds.Tables[" 招投标"].Rows.Count.ToString();
            lb_tb = tb;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='融资'", conn);
            da.Fill(ds, "融资");
            string rz = ds.Tables["融资"].Rows.Count.ToString();
            lb_rz = rz;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='厂店租售'", conn);
            da.Fill(ds, "厂店租售");
            string cd = ds.Tables["厂店租售"].Rows.Count.ToString();
            lb_cd = cd;

            da = new SqlDataAdapter("select * from Product where p_UserID='" + UserID + "' and p_Type='其它'", conn);
            da.Fill(ds, "其它");
            string qt = ds.Tables["其它"].Rows.Count.ToString();
            lb_qt = qt;

            conn.Close();
            conn.Dispose();
            da.Dispose();
            ds.Dispose();
        }
    }
    private void list_bind()
    {

        SqlConnection conn = Class1.DBconnection();

        int uid = int.Parse(Request.QueryString["p_UserID"]);
            
            if (Request.QueryString["type"] != "")
            {
                tt = Request.QueryString["type"];
                 sql = "select * from Product where p_UserID=" + uid + " and  p_Type='" + tt + "' order by p_ID desc";
            }
 
          else
            {
                 sql = "select * from Product where p_UserID=" + uid + " order by p_ID desc";
            }
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows[i]["p_Title"].ToString().Length > 30)
            {
                ds.Tables[0].Rows[i]["p_Title"] = ds.Tables[0].Rows[i]["p_Title"].ToString().Substring(0, 30) + "...";
            }
        }

        if (dt.Rows.Count > 0)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;

            pds.AllowPaging = true;
            pds.PageSize = 20;
            int curPage;

            if (Request.QueryString["page"] != null)
            {
                curPage = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                curPage = 1;
            }

            pds.CurrentPageIndex = curPage - 1;
            this.dl_pro.DataSource = pds;
            this.dl_pro.DataBind();
            this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a>&nbsp;";
            this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a>&nbsp;";
            this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a>&nbsp;";
            this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a>&nbsp;&nbsp;";
            if (curPage == 1)
            {
                this.Label1.Text += "<a>首页</a>&nbsp;&nbsp;";
                this.Label1.Text += "<a>上一页</a>&nbsp;&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='tradealmove.aspx?page=1&u_id=" + uid + "&type=" + tt + "'>首页</a>&nbsp;&nbsp;";
                this.Label1.Text += "<a href='tradealmove.aspx?page=" + (curPage - 1).ToString() + "&u_id=" + uid + "&type=" + tt + "'>上一页</a>&nbsp;&nbsp;";
            }
            if (curPage == pds.PageCount)
            {
                this.Label1.Text += "<a>下一页</a>&nbsp;&nbsp;";
                this.Label1.Text += "<a>尾页</a>&nbsp;&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='tradealmove.aspx?page=" + (curPage + 1).ToString() + "&u_id=" + uid + "&type=" + tt + "'>下一页</a>&nbsp;&nbsp;";
                this.Label1.Text += "<a href='tradealmove.aspx?page=" + pds.PageCount.ToString() + "&u_id=" + uid + "&type=" + tt + "'>尾页</a>&nbsp;&nbsp;";
            }

            string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
            for (int i = 1; i <= pds.PageCount; i++)
            {
                if (i == curPage)
                {
                    HtmlSelectString += "<option value=?page=" + i + "&u_id=" + uid + "&type=" + tt + " selected>第" + i + "页</option>";
                }
                else
                {
                    HtmlSelectString += "<option value=?page=" + i + "&u_id=" + uid + "&type=" + tt + ">第" + i + "页</option>";
                }
            }
            HtmlSelectString += "</select>";

            this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
        }
        else
        {
            this.Label1.Text = "当前没有记录";
        }
        ds.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
    }
}
